{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-03-29T03:09:26.709435Z",
     "start_time": "2024-03-29T03:09:22.365503Z"
    }
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "from torch import nn\n",
    "from d2l import torch as d2l"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 4.3.1. 模型"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "97966f21ba3c18e3"
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "net = nn.Sequential(nn.Flatten(),\n",
    "                    nn.Linear(784, 256),\n",
    "                    nn.ReLU(),\n",
    "                    nn.Linear(256, 10))\n",
    "\n",
    "def init_weights(m):\n",
    "    if type(m) == nn.Linear:\n",
    "        nn.init.normal_(m.weight, std=0.01)\n",
    "\n",
    "net.apply(init_weights);"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-03-29T03:11:40.328535Z",
     "start_time": "2024-03-29T03:11:40.305756Z"
    }
   },
   "id": "748e994206641018",
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "from d2l.torch import get_dataloader_workers\n",
    "from torch.utils import data\n",
    "import torchvision\n",
    "from torchvision import transforms\n",
    "\n",
    "\n",
    "def accuracy(y_hat, y):  #@save\n",
    "    \"\"\"计算预测正确的数量\"\"\"\n",
    "    if len(y_hat.shape) > 1 and y_hat.shape[1] > 1:\n",
    "        y_hat = y_hat.argmax(axis=1)\n",
    "    cmp = y_hat.type(y.dtype) == y\n",
    "    return float(cmp.type(y.dtype).sum())\n",
    "\n",
    "\n",
    "def train_epoch_ch3(net, train_iter, loss, updater):\n",
    "    if isinstance(net, torch.nn.Module):\n",
    "        net.train()\n",
    "    metric = d2l.Accumulator(3)\n",
    "    for X, y in train_iter:\n",
    "        y_hat = net(X)\n",
    "        l = loss(y_hat, y)\n",
    "        if isinstance(updater, torch.optim.Optimizer):\n",
    "            updater.zero_grad()\n",
    "            l.mean().backward()\n",
    "            updater.step()\n",
    "        else:\n",
    "            l.sum().backward()\n",
    "            updater(X.shape[0])\n",
    "        metric.add(float(l.sum()), accuracy(y_hat, y), y.numel())\n",
    "    return metric[0] / metric[2], metric[1] / metric[2]\n",
    "\n",
    "\n",
    "def evaluate_accuracy(net, data_iter):  #@save\n",
    "    \"\"\"计算在指定数据集上模型的精度\"\"\"\n",
    "    if isinstance(net, torch.nn.Module):\n",
    "        net.eval()  # 将模型设置为评估模式\n",
    "    metric = d2l.Accumulator(2)  # 正确预测数、预测总数\n",
    "    with torch.no_grad():\n",
    "        for X, y in data_iter:\n",
    "            metric.add(accuracy(net(X), y), y.numel())\n",
    "    return metric[0] / metric[1]\n",
    "\n",
    "\n",
    "def train_ch3(net, train_iter, test_iter, loss, num_epochs, updater):\n",
    "    animator = d2l.Animator(xlabel='epoch', xlim=[1, num_epochs], ylim=[0.3, 0.9],\n",
    "                        legend=['train loss', 'train acc', 'test acc'])\n",
    "    for epoch in range(num_epochs):\n",
    "        train_metrics = train_epoch_ch3(net, train_iter, loss, updater)\n",
    "        test_acc = evaluate_accuracy(net, test_iter)\n",
    "        animator.add(epoch + 1, train_metrics + (test_acc,))\n",
    "    train_loss, train_acc = train_metrics\n",
    "    assert train_loss < 0.5, train_loss\n",
    "    assert 1 >= train_acc > 0.7, train_acc\n",
    "    assert 1 >= test_acc > 0.7, test_acc\n",
    "    \n",
    "\n",
    "def load_data_fashion_mnist(batch_size, resize=None):  #@save\n",
    "    \"\"\"下载Fashion-MNIST数据集，然后将其加载到内存中\"\"\"\n",
    "    trans = [transforms.ToTensor()]\n",
    "    if resize:\n",
    "        trans.insert(0, transforms.Resize(resize))\n",
    "    trans = transforms.Compose(trans)\n",
    "    mnist_train = torchvision.datasets.FashionMNIST(\n",
    "        root=r\"G:\\baidu\\dataset\\Fashin-MNIST\", train=True, transform=trans, download=True)\n",
    "    mnist_test = torchvision.datasets.FashionMNIST(\n",
    "        root=r\"G:\\baidu\\dataset\\Fashin-MNIST\", train=False, transform=trans, download=True)\n",
    "    return (data.DataLoader(mnist_train, batch_size, shuffle=True,\n",
    "                            num_workers=get_dataloader_workers()),\n",
    "            data.DataLoader(mnist_test, batch_size, shuffle=False,\n",
    "                            num_workers=get_dataloader_workers()))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-03-29T03:13:15.238371Z",
     "start_time": "2024-03-29T03:13:15.075785Z"
    }
   },
   "id": "b1baf8f6b2501f7f",
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 350x250 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"236.7pt\" height=\"180.25pt\" viewBox=\"0 0 236.7 180.25\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2024-03-29T11:15:22.823313</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 180.25 \nL 236.7 180.25 \nL 236.7 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 29.2 145.8 \nL 224.5 145.8 \nL 224.5 7.2 \nL 29.2 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 50.9 145.8 \nL 50.9 7.2 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"m61a028bc80\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m61a028bc80\" x=\"50.9\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- 2 -->\n      <g transform=\"translate(48.4 159.675) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-32\" d=\"M 300 250 \nQ 325 625 650 925 \nQ 975 1225 1475 1862 \nQ 1975 2500 2125 2850 \nQ 2275 3200 2237 3450 \nQ 2200 3700 2000 3862 \nQ 1800 4025 1537 4000 \nQ 1275 3975 1037 3800 \nQ 800 3625 675 3275 \nL 200 3350 \nQ 400 3925 712 4187 \nQ 1025 4450 1450 4475 \nQ 1700 4500 1900 4462 \nQ 2100 4425 2312 4287 \nQ 2525 4150 2662 3875 \nQ 2800 3600 2762 3212 \nQ 2725 2825 2375 2287 \nQ 2025 1750 1025 600 \nL 2825 600 \nL 2825 150 \nL 300 150 \nL 300 250 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-32\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 94.3 145.8 \nL 94.3 7.2 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#m61a028bc80\" x=\"94.3\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 4 -->\n      <g transform=\"translate(91.8 159.675) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-34\" d=\"M 2000 1100 \nL 75 1100 \nL 75 1525 \nL 2100 4450 \nL 2475 4450 \nL 2475 1525 \nL 3075 1525 \nL 3075 1100 \nL 2475 1100 \nL 2475 150 \nL 2000 150 \nL 2000 1100 \nz\nM 2000 1525 \nL 2000 3500 \nL 600 1525 \nL 2000 1525 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-34\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 137.7 145.8 \nL 137.7 7.2 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m61a028bc80\" x=\"137.7\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 6 -->\n      <g transform=\"translate(135.2 159.675) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-36\" d=\"M 250 1612 \nQ 275 1975 387 2225 \nQ 500 2475 725 2850 \nL 1750 4450 \nL 2325 4450 \nL 1275 2800 \nQ 1950 2975 2350 2750 \nQ 2750 2525 2887 2237 \nQ 3025 1950 3037 1612 \nQ 3050 1275 2937 950 \nQ 2825 625 2537 362 \nQ 2250 100 1737 75 \nQ 1225 50 862 262 \nQ 500 475 362 862 \nQ 225 1250 250 1612 \nz\nM 1025 787 \nQ 1250 550 1625 525 \nQ 2000 500 2250 775 \nQ 2500 1050 2500 1575 \nQ 2500 2100 2187 2300 \nQ 1875 2500 1487 2450 \nQ 1100 2400 925 2075 \nQ 750 1750 775 1387 \nQ 800 1025 1025 787 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-36\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 181.1 145.8 \nL 181.1 7.2 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#m61a028bc80\" x=\"181.1\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 8 -->\n      <g transform=\"translate(178.6 159.675) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-38\" d=\"M 175 1375 \nQ 175 1675 325 1962 \nQ 475 2250 825 2425 \nQ 525 2600 425 2812 \nQ 325 3025 312 3300 \nQ 300 3575 387 3775 \nQ 475 3975 650 4150 \nQ 825 4325 1037 4387 \nQ 1250 4450 1500 4450 \nQ 1750 4450 1950 4400 \nQ 2150 4350 2375 4187 \nQ 2600 4025 2700 3725 \nQ 2800 3425 2687 3025 \nQ 2575 2625 2100 2400 \nQ 2525 2275 2700 2012 \nQ 2875 1750 2875 1375 \nQ 2875 1000 2762 775 \nQ 2650 550 2512 400 \nQ 2375 250 2137 162 \nQ 1900 75 1537 75 \nQ 1175 75 912 162 \nQ 650 250 475 425 \nQ 300 600 237 837 \nQ 175 1075 175 1375 \nz\nM 687 1400 \nQ 675 1100 787 875 \nQ 900 650 1200 587 \nQ 1500 525 1825 600 \nQ 2150 675 2275 950 \nQ 2400 1225 2362 1500 \nQ 2325 1775 2050 1962 \nQ 1775 2150 1450 2125 \nQ 1125 2100 912 1900 \nQ 700 1700 687 1400 \nz\nM 775 3350 \nQ 775 3100 950 2875 \nQ 1125 2650 1500 2650 \nQ 1875 2650 2062 2875 \nQ 2250 3100 2237 3412 \nQ 2225 3725 2012 3875 \nQ 1800 4025 1437 4000 \nQ 1075 3975 925 3787 \nQ 775 3600 775 3350 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-38\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_9\">\n      <path d=\"M 224.5 145.8 \nL 224.5 7.2 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#m61a028bc80\" x=\"224.5\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 10 -->\n      <g transform=\"translate(219.5 159.675) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-31\" d=\"M 1400 3600 \nQ 1075 3275 575 2975 \nL 575 3450 \nQ 1200 3875 1600 4450 \nL 1900 4450 \nL 1900 150 \nL 1400 150 \nL 1400 3600 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"SimHei-30\" d=\"M 225 2537 \nQ 250 3200 412 3587 \nQ 575 3975 875 4225 \nQ 1175 4475 1612 4475 \nQ 2050 4475 2375 4112 \nQ 2700 3750 2800 3200 \nQ 2900 2650 2862 1937 \nQ 2825 1225 2612 775 \nQ 2400 325 1975 150 \nQ 1550 -25 1125 187 \nQ 700 400 525 750 \nQ 350 1100 275 1487 \nQ 200 1875 225 2537 \nz\nM 750 2687 \nQ 675 2000 800 1462 \nQ 925 925 1212 700 \nQ 1500 475 1800 612 \nQ 2100 750 2237 1162 \nQ 2375 1575 2375 2062 \nQ 2375 2550 2337 2950 \nQ 2300 3350 2112 3675 \nQ 1925 4000 1612 4012 \nQ 1300 4025 1062 3700 \nQ 825 3375 750 2687 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-31\"/>\n       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_6\">\n     <!-- epoch -->\n     <g transform=\"translate(114.35 171.8) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"SimHei-65\" d=\"M 2850 1075 \nQ 2800 625 2450 350 \nQ 2100 75 1625 75 \nQ 1025 75 637 462 \nQ 250 850 250 1525 \nQ 250 2200 637 2587 \nQ 1025 2975 1625 2975 \nQ 2150 2975 2487 2637 \nQ 2825 2300 2825 1525 \nL 800 1525 \nQ 800 975 1037 750 \nQ 1275 525 1625 525 \nQ 1900 525 2075 662 \nQ 2250 800 2300 1075 \nL 2850 1075 \nz\nM 2250 1925 \nQ 2200 2275 2025 2412 \nQ 1850 2550 1575 2550 \nQ 1325 2550 1125 2412 \nQ 925 2275 825 1925 \nL 2250 1925 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-70\" d=\"M 2825 1525 \nQ 2825 800 2475 425 \nQ 2125 50 1625 50 \nQ 1350 50 1150 162 \nQ 950 275 800 500 \nL 800 -800 \nL 300 -800 \nL 300 2925 \nL 800 2925 \nL 800 2550 \nQ 950 2775 1150 2875 \nQ 1350 2975 1625 2975 \nQ 2125 2975 2475 2612 \nQ 2825 2250 2825 1525 \nz\nM 2275 1525 \nQ 2275 2000 2087 2262 \nQ 1900 2525 1525 2525 \nQ 1225 2525 1012 2262 \nQ 800 2000 800 1525 \nQ 800 1050 1012 775 \nQ 1225 500 1525 500 \nQ 1900 500 2087 775 \nQ 2275 1050 2275 1525 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-6f\" d=\"M 2925 1525 \nQ 2925 875 2525 475 \nQ 2125 75 1575 75 \nQ 1025 75 625 475 \nQ 225 875 225 1525 \nQ 225 2175 625 2575 \nQ 1025 2975 1575 2975 \nQ 2125 2975 2525 2575 \nQ 2925 2175 2925 1525 \nz\nM 2375 1525 \nQ 2375 2025 2125 2275 \nQ 1875 2525 1575 2525 \nQ 1275 2525 1025 2275 \nQ 775 2025 775 1525 \nQ 775 1025 1025 775 \nQ 1275 525 1575 525 \nQ 1875 525 2125 775 \nQ 2375 1025 2375 1525 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-63\" d=\"M 2850 1250 \nQ 2850 725 2487 400 \nQ 2125 75 1575 75 \nQ 1025 75 625 462 \nQ 225 850 225 1525 \nQ 225 2200 625 2587 \nQ 1025 2975 1575 2975 \nQ 2125 2975 2450 2687 \nQ 2775 2400 2775 2000 \nL 2225 2000 \nQ 2200 2300 2012 2412 \nQ 1825 2525 1575 2525 \nQ 1275 2525 1025 2287 \nQ 775 2050 775 1525 \nQ 775 1000 1025 762 \nQ 1275 525 1575 525 \nQ 1900 525 2100 700 \nQ 2300 875 2300 1250 \nL 2850 1250 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-68\" d=\"M 2800 125 \nL 2300 125 \nL 2300 1925 \nQ 2300 2225 2150 2400 \nQ 2000 2575 1750 2575 \nQ 1425 2575 1137 2237 \nQ 850 1900 850 1400 \nL 850 125 \nL 350 125 \nL 350 4400 \nL 850 4400 \nL 850 2400 \nQ 1050 2675 1287 2825 \nQ 1525 2975 1900 2975 \nQ 2350 2975 2575 2725 \nQ 2800 2475 2800 2100 \nL 2800 125 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#SimHei-65\"/>\n      <use xlink:href=\"#SimHei-70\" x=\"50\"/>\n      <use xlink:href=\"#SimHei-6f\" x=\"100\"/>\n      <use xlink:href=\"#SimHei-63\" x=\"150\"/>\n      <use xlink:href=\"#SimHei-68\" x=\"200\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_11\">\n      <path d=\"M 29.2 122.7 \nL 224.5 122.7 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <defs>\n       <path id=\"mb9ceb33866\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mb9ceb33866\" x=\"29.2\" y=\"122.7\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 0.4 -->\n      <g transform=\"translate(7.2 126.1375) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-2e\" d=\"M 1075 125 \nL 500 125 \nL 500 675 \nL 1075 675 \nL 1075 125 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-30\"/>\n       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n       <use xlink:href=\"#SimHei-34\" x=\"100\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_13\">\n      <path d=\"M 29.2 76.5 \nL 224.5 76.5 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#mb9ceb33866\" x=\"29.2\" y=\"76.5\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 0.6 -->\n      <g transform=\"translate(7.2 79.9375) scale(0.1 -0.1)\">\n       <use xlink:href=\"#SimHei-30\"/>\n       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n       <use xlink:href=\"#SimHei-36\" x=\"100\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_15\">\n      <path d=\"M 29.2 30.3 \nL 224.5 30.3 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#mb9ceb33866\" x=\"29.2\" y=\"30.3\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 0.8 -->\n      <g transform=\"translate(7.2 33.7375) scale(0.1 -0.1)\">\n       <use xlink:href=\"#SimHei-30\"/>\n       <use xlink:href=\"#SimHei-2e\" x=\"50\"/>\n       <use xlink:href=\"#SimHei-38\" x=\"100\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_17\">\n    <path d=\"M 34.503038 -1 \nL 50.9 77.437816 \nL 72.6 94.9682 \nL 94.3 104.643867 \nL 116 111.469886 \nL 137.7 114.711383 \nL 159.4 118.473116 \nL 181.1 121.972869 \nL 202.8 124.673517 \nL 224.5 126.775342 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_18\">\n    <path d=\"M 29.2 67.82595 \nL 50.9 32.0941 \nL 72.6 26.1651 \nL 94.3 22.99655 \nL 116 20.53255 \nL 137.7 19.7202 \nL 159.4 18.2495 \nL 181.1 17.0021 \nL 202.8 16.2475 \nL 224.5 15.1541 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"line2d_19\">\n    <path d=\"M 29.2 38.4543 \nL 50.9 33.6957 \nL 72.6 24.9639 \nL 94.3 25.3566 \nL 116 22.1457 \nL 137.7 26.4423 \nL 159.4 25.218 \nL 181.1 20.4825 \nL 202.8 21.1986 \nL 224.5 19.9974 \n\" clip-path=\"url(#p133ee7364b)\" style=\"fill: none; stroke-dasharray: 9.6,2.4,1.5,2.4; stroke-dashoffset: 0; stroke: #008000; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 29.2 145.8 \nL 29.2 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 224.5 145.8 \nL 224.5 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 29.2 145.8 \nL 224.5 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 29.2 7.2 \nL 224.5 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"legend_1\">\n    <g id=\"patch_7\">\n     <path d=\"M 135.5 97.875 \nL 217.5 97.875 \nQ 219.5 97.875 219.5 95.875 \nL 219.5 57.125 \nQ 219.5 55.125 217.5 55.125 \nL 135.5 55.125 \nQ 133.5 55.125 133.5 57.125 \nL 133.5 95.875 \nQ 133.5 97.875 135.5 97.875 \nz\n\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n    </g>\n    <g id=\"line2d_20\">\n     <path d=\"M 137.5 62.625 \nL 147.5 62.625 \nL 157.5 62.625 \n\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n    </g>\n    <g id=\"text_10\">\n     <!-- train loss -->\n     <g transform=\"translate(165.5 66.125) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"SimHei-74\" d=\"M 2750 200 \nQ 2625 150 2462 112 \nQ 2300 75 2025 75 \nQ 1575 75 1300 325 \nQ 1025 575 1025 1025 \nL 1025 2525 \nL 175 2525 \nL 175 2925 \nL 1025 2925 \nL 1025 3900 \nL 1525 3900 \nL 1525 2925 \nL 2550 2925 \nL 2550 2525 \nL 1525 2525 \nL 1525 1000 \nQ 1525 800 1625 662 \nQ 1725 525 2000 525 \nQ 2275 525 2450 575 \nQ 2625 625 2750 700 \nL 2750 200 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-72\" d=\"M 2500 2425 \nQ 2025 2500 1700 2287 \nQ 1375 2075 1150 1550 \nL 1150 125 \nL 650 125 \nL 650 2925 \nL 1150 2925 \nL 1150 2200 \nQ 1375 2600 1712 2787 \nQ 2050 2975 2500 2975 \nL 2500 2425 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-61\" d=\"M 2875 125 \nL 2275 125 \nQ 2225 175 2200 262 \nQ 2175 350 2175 475 \nQ 2000 275 1750 175 \nQ 1500 75 1225 75 \nQ 825 75 550 275 \nQ 275 475 275 850 \nQ 275 1225 525 1450 \nQ 775 1675 1300 1750 \nQ 1650 1800 1912 1875 \nQ 2175 1950 2175 2075 \nQ 2175 2225 2062 2375 \nQ 1950 2525 1575 2525 \nQ 1275 2525 1137 2412 \nQ 1000 2300 950 2100 \nL 400 2100 \nQ 450 2500 762 2737 \nQ 1075 2975 1575 2975 \nQ 2125 2975 2400 2725 \nQ 2675 2475 2675 2025 \nL 2675 650 \nQ 2675 500 2725 375 \nQ 2775 250 2875 125 \nz\nM 2175 1050 \nL 2175 1550 \nQ 2025 1500 1887 1462 \nQ 1750 1425 1425 1375 \nQ 1050 1325 937 1200 \nQ 825 1075 825 900 \nQ 825 750 937 637 \nQ 1050 525 1275 525 \nQ 1500 525 1762 650 \nQ 2025 775 2175 1050 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-69\" d=\"M 1800 3725 \nL 1300 3725 \nL 1300 4375 \nL 1800 4375 \nL 1800 3725 \nz\nM 1800 125 \nL 1300 125 \nL 1300 2925 \nL 1800 2925 \nL 1800 125 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-6e\" d=\"M 2800 125 \nL 2300 125 \nL 2300 1925 \nQ 2300 2225 2150 2400 \nQ 2000 2575 1750 2575 \nQ 1425 2575 1137 2237 \nQ 850 1900 850 1400 \nL 850 125 \nL 350 125 \nL 350 2925 \nL 850 2925 \nL 850 2400 \nQ 1050 2675 1287 2825 \nQ 1525 2975 1900 2975 \nQ 2350 2975 2575 2725 \nQ 2800 2475 2800 2100 \nL 2800 125 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-20\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-6c\" d=\"M 1825 125 \nL 1325 125 \nL 1325 4400 \nL 1825 4400 \nL 1825 125 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-73\" d=\"M 2750 900 \nQ 2750 500 2437 287 \nQ 2125 75 1650 75 \nQ 1050 75 725 312 \nQ 400 550 400 1000 \nL 900 1000 \nQ 900 700 1112 600 \nQ 1325 500 1625 500 \nQ 1925 500 2075 612 \nQ 2225 725 2225 900 \nQ 2225 1025 2100 1150 \nQ 1975 1275 1475 1350 \nQ 900 1425 687 1637 \nQ 475 1850 475 2200 \nQ 475 2500 762 2737 \nQ 1050 2975 1600 2975 \nQ 2100 2975 2387 2750 \nQ 2675 2525 2675 2150 \nL 2175 2150 \nQ 2175 2375 2012 2462 \nQ 1850 2550 1600 2550 \nQ 1275 2550 1137 2437 \nQ 1000 2325 1000 2175 \nQ 1000 2000 1125 1900 \nQ 1250 1800 1650 1750 \nQ 2300 1650 2525 1437 \nQ 2750 1225 2750 900 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#SimHei-74\"/>\n      <use xlink:href=\"#SimHei-72\" x=\"50\"/>\n      <use xlink:href=\"#SimHei-61\" x=\"100\"/>\n      <use xlink:href=\"#SimHei-69\" x=\"150\"/>\n      <use xlink:href=\"#SimHei-6e\" x=\"200\"/>\n      <use xlink:href=\"#SimHei-20\" x=\"250\"/>\n      <use xlink:href=\"#SimHei-6c\" x=\"300\"/>\n      <use xlink:href=\"#SimHei-6f\" x=\"350\"/>\n      <use xlink:href=\"#SimHei-73\" x=\"400\"/>\n      <use xlink:href=\"#SimHei-73\" x=\"450\"/>\n     </g>\n    </g>\n    <g id=\"line2d_21\">\n     <path d=\"M 137.5 75.875 \nL 147.5 75.875 \nL 157.5 75.875 \n\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n    </g>\n    <g id=\"text_11\">\n     <!-- train acc -->\n     <g transform=\"translate(165.5 79.375) scale(0.1 -0.1)\">\n      <use xlink:href=\"#SimHei-74\"/>\n      <use xlink:href=\"#SimHei-72\" x=\"50\"/>\n      <use xlink:href=\"#SimHei-61\" x=\"100\"/>\n      <use xlink:href=\"#SimHei-69\" x=\"150\"/>\n      <use xlink:href=\"#SimHei-6e\" x=\"200\"/>\n      <use xlink:href=\"#SimHei-20\" x=\"250\"/>\n      <use xlink:href=\"#SimHei-61\" x=\"300\"/>\n      <use xlink:href=\"#SimHei-63\" x=\"350\"/>\n      <use xlink:href=\"#SimHei-63\" x=\"400\"/>\n     </g>\n    </g>\n    <g id=\"line2d_22\">\n     <path d=\"M 137.5 89.125 \nL 147.5 89.125 \nL 157.5 89.125 \n\" style=\"fill: none; stroke-dasharray: 9.6,2.4,1.5,2.4; stroke-dashoffset: 0; stroke: #008000; stroke-width: 1.5\"/>\n    </g>\n    <g id=\"text_12\">\n     <!-- test acc -->\n     <g transform=\"translate(165.5 92.625) scale(0.1 -0.1)\">\n      <use xlink:href=\"#SimHei-74\"/>\n      <use xlink:href=\"#SimHei-65\" x=\"50\"/>\n      <use xlink:href=\"#SimHei-73\" x=\"100\"/>\n      <use xlink:href=\"#SimHei-74\" x=\"150\"/>\n      <use xlink:href=\"#SimHei-20\" x=\"200\"/>\n      <use xlink:href=\"#SimHei-61\" x=\"250\"/>\n      <use xlink:href=\"#SimHei-63\" x=\"300\"/>\n      <use xlink:href=\"#SimHei-63\" x=\"350\"/>\n     </g>\n    </g>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p133ee7364b\">\n   <rect x=\"29.2\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "batch_size, lr, num_epochs = 256, 0.1, 10\n",
    "loss = nn.CrossEntropyLoss(reduction='none')\n",
    "trainer = torch.optim.SGD(net.parameters(), lr=lr)\n",
    "\n",
    "train_iter, test_iter = load_data_fashion_mnist(batch_size)\n",
    "train_ch3(net, train_iter, test_iter, loss, num_epochs, trainer)"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "782c46f79d4494d",
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "OrderedDict([('1.weight',\n              tensor([[-0.0006,  0.0055,  0.0037,  ...,  0.0034, -0.0266,  0.0127],\n                      [ 0.0114, -0.0156,  0.0070,  ..., -0.0265, -0.0021, -0.0082],\n                      [-0.0134, -0.0131,  0.0063,  ..., -0.0082, -0.0121, -0.0033],\n                      ...,\n                      [-0.0120, -0.0123,  0.0127,  ...,  0.0006,  0.0052, -0.0086],\n                      [ 0.0026, -0.0020, -0.0030,  ...,  0.0054,  0.0019,  0.0120],\n                      [-0.0072, -0.0085,  0.0038,  ...,  0.0109, -0.0117,  0.0047]])),\n             ('1.bias',\n              tensor([ 0.0607,  0.1286,  0.2476,  0.1616, -0.0258, -0.0700,  0.0696, -0.0066,\n                       0.0940,  0.1554, -0.0079, -0.0667, -0.0707,  0.0915, -0.0355, -0.0189,\n                       0.0402,  0.1204,  0.1013,  0.0790,  0.0589,  0.0201,  0.0204,  0.0205,\n                       0.0530, -0.0864,  0.0161, -0.0359, -0.1493,  0.0247,  0.0145,  0.2111,\n                       0.0305, -0.0961,  0.0056, -0.0672,  0.0166,  0.0747,  0.0718,  0.0617,\n                      -0.0185,  0.1399,  0.0526,  0.0965, -0.0359,  0.0222,  0.0538,  0.0057,\n                       0.0883,  0.1057,  0.1154, -0.0157,  0.0936,  0.0117,  0.0383,  0.0122,\n                      -0.0639,  0.0471,  0.0185,  0.0079,  0.0026, -0.1151,  0.0255, -0.0345,\n                      -0.1521, -0.0293,  0.1107,  0.0379,  0.1456, -0.0105, -0.0225,  0.1259,\n                      -0.0543, -0.0385,  0.1724, -0.0258, -0.0506, -0.0333,  0.0453,  0.1026,\n                       0.0670,  0.0260,  0.1084,  0.0278,  0.0205, -0.0665, -0.0274,  0.1057,\n                      -0.0316,  0.0092, -0.0148, -0.0641,  0.1337,  0.0043,  0.0140, -0.0171,\n                      -0.1720, -0.0839,  0.1123,  0.0055, -0.1587,  0.1380,  0.0174, -0.0567,\n                      -0.0341,  0.0286,  0.0141, -0.2017,  0.1568,  0.1002, -0.0259,  0.0415,\n                       0.0469,  0.1197,  0.0006,  0.0338, -0.1114,  0.0311,  0.0499, -0.1141,\n                       0.1750,  0.0479,  0.1121,  0.1134, -0.0500,  0.0156,  0.0493,  0.1889,\n                      -0.0059,  0.0379, -0.0325,  0.1028,  0.0143,  0.0164, -0.1131,  0.1218,\n                      -0.0004, -0.0173, -0.0034,  0.1045,  0.0955,  0.0886,  0.1122,  0.0666,\n                      -0.0073,  0.1199,  0.1656, -0.2300,  0.1822,  0.0317,  0.0713, -0.0393,\n                       0.2558, -0.0127, -0.0636,  0.0502,  0.0054, -0.0789,  0.0009,  0.0519,\n                      -0.0067,  0.0755, -0.1523,  0.0010,  0.0187,  0.0111,  0.0094, -0.0169,\n                       0.0299, -0.0163, -0.0209, -0.0492,  0.0109,  0.2074, -0.0632,  0.1095,\n                      -0.0524,  0.1050,  0.0589,  0.1302,  0.0370, -0.0008,  0.0223, -0.0145,\n                       0.2577, -0.0406, -0.0291, -0.0317,  0.0976,  0.0351,  0.0560, -0.1271,\n                       0.1153,  0.0361,  0.0609,  0.0751,  0.0609,  0.1100,  0.0110,  0.0250,\n                      -0.0094,  0.2946, -0.2031,  0.0099,  0.0896, -0.0348,  0.0711,  0.0115,\n                      -0.0448,  0.1236,  0.0075,  0.0552,  0.0800,  0.0289,  0.1108,  0.0651,\n                       0.0230, -0.0247,  0.0257,  0.0123,  0.1328,  0.0788,  0.0704, -0.0142,\n                       0.1715,  0.0357,  0.0107,  0.0753, -0.0232,  0.2400,  0.0752, -0.0332,\n                       0.0244,  0.1322,  0.0039,  0.1442,  0.0524, -0.0306,  0.0375, -0.0058,\n                      -0.0337,  0.1343, -0.0978, -0.0171,  0.0065, -0.0408,  0.0493, -0.0721,\n                      -0.0165,  0.1206, -0.0069,  0.0884,  0.0728,  0.0726,  0.0386,  0.1413])),\n             ('3.weight',\n              tensor([[-0.2406,  0.2085, -0.1045,  ...,  0.0097, -0.0388,  0.2840],\n                      [ 0.0922, -0.2183, -0.2021,  ..., -0.0121, -0.1086,  0.1455],\n                      [ 0.0428, -0.0640,  0.0913,  ...,  0.0143, -0.1118, -0.3261],\n                      ...,\n                      [-0.0710,  0.0520,  0.3712,  ..., -0.0345,  0.2290, -0.0791],\n                      [-0.2581,  0.1035,  0.3199,  ..., -0.0599,  0.1065, -0.0300],\n                      [-0.1069, -0.1370, -0.3880,  ..., -0.0568,  0.0072, -0.0546]])),\n             ('3.bias',\n              tensor([ 0.1068, -0.1433,  0.1138,  0.1802, -0.5881,  1.0040,  0.2596, -0.0113,\n                      -0.2763, -0.6917]))])"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.state_dict()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-03-29T03:16:11.947396Z",
     "start_time": "2024-03-29T03:16:11.928295Z"
    }
   },
   "id": "973efaf692a440a6",
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.weight -> Parameter containing:\n",
      "tensor([[-0.0006,  0.0055,  0.0037,  ...,  0.0034, -0.0266,  0.0127],\n",
      "        [ 0.0114, -0.0156,  0.0070,  ..., -0.0265, -0.0021, -0.0082],\n",
      "        [-0.0134, -0.0131,  0.0063,  ..., -0.0082, -0.0121, -0.0033],\n",
      "        ...,\n",
      "        [-0.0120, -0.0123,  0.0127,  ...,  0.0006,  0.0052, -0.0086],\n",
      "        [ 0.0026, -0.0020, -0.0030,  ...,  0.0054,  0.0019,  0.0120],\n",
      "        [-0.0072, -0.0085,  0.0038,  ...,  0.0109, -0.0117,  0.0047]],\n",
      "       requires_grad=True)\n",
      "1.bias -> Parameter containing:\n",
      "tensor([ 0.0607,  0.1286,  0.2476,  0.1616, -0.0258, -0.0700,  0.0696, -0.0066,\n",
      "         0.0940,  0.1554, -0.0079, -0.0667, -0.0707,  0.0915, -0.0355, -0.0189,\n",
      "         0.0402,  0.1204,  0.1013,  0.0790,  0.0589,  0.0201,  0.0204,  0.0205,\n",
      "         0.0530, -0.0864,  0.0161, -0.0359, -0.1493,  0.0247,  0.0145,  0.2111,\n",
      "         0.0305, -0.0961,  0.0056, -0.0672,  0.0166,  0.0747,  0.0718,  0.0617,\n",
      "        -0.0185,  0.1399,  0.0526,  0.0965, -0.0359,  0.0222,  0.0538,  0.0057,\n",
      "         0.0883,  0.1057,  0.1154, -0.0157,  0.0936,  0.0117,  0.0383,  0.0122,\n",
      "        -0.0639,  0.0471,  0.0185,  0.0079,  0.0026, -0.1151,  0.0255, -0.0345,\n",
      "        -0.1521, -0.0293,  0.1107,  0.0379,  0.1456, -0.0105, -0.0225,  0.1259,\n",
      "        -0.0543, -0.0385,  0.1724, -0.0258, -0.0506, -0.0333,  0.0453,  0.1026,\n",
      "         0.0670,  0.0260,  0.1084,  0.0278,  0.0205, -0.0665, -0.0274,  0.1057,\n",
      "        -0.0316,  0.0092, -0.0148, -0.0641,  0.1337,  0.0043,  0.0140, -0.0171,\n",
      "        -0.1720, -0.0839,  0.1123,  0.0055, -0.1587,  0.1380,  0.0174, -0.0567,\n",
      "        -0.0341,  0.0286,  0.0141, -0.2017,  0.1568,  0.1002, -0.0259,  0.0415,\n",
      "         0.0469,  0.1197,  0.0006,  0.0338, -0.1114,  0.0311,  0.0499, -0.1141,\n",
      "         0.1750,  0.0479,  0.1121,  0.1134, -0.0500,  0.0156,  0.0493,  0.1889,\n",
      "        -0.0059,  0.0379, -0.0325,  0.1028,  0.0143,  0.0164, -0.1131,  0.1218,\n",
      "        -0.0004, -0.0173, -0.0034,  0.1045,  0.0955,  0.0886,  0.1122,  0.0666,\n",
      "        -0.0073,  0.1199,  0.1656, -0.2300,  0.1822,  0.0317,  0.0713, -0.0393,\n",
      "         0.2558, -0.0127, -0.0636,  0.0502,  0.0054, -0.0789,  0.0009,  0.0519,\n",
      "        -0.0067,  0.0755, -0.1523,  0.0010,  0.0187,  0.0111,  0.0094, -0.0169,\n",
      "         0.0299, -0.0163, -0.0209, -0.0492,  0.0109,  0.2074, -0.0632,  0.1095,\n",
      "        -0.0524,  0.1050,  0.0589,  0.1302,  0.0370, -0.0008,  0.0223, -0.0145,\n",
      "         0.2577, -0.0406, -0.0291, -0.0317,  0.0976,  0.0351,  0.0560, -0.1271,\n",
      "         0.1153,  0.0361,  0.0609,  0.0751,  0.0609,  0.1100,  0.0110,  0.0250,\n",
      "        -0.0094,  0.2946, -0.2031,  0.0099,  0.0896, -0.0348,  0.0711,  0.0115,\n",
      "        -0.0448,  0.1236,  0.0075,  0.0552,  0.0800,  0.0289,  0.1108,  0.0651,\n",
      "         0.0230, -0.0247,  0.0257,  0.0123,  0.1328,  0.0788,  0.0704, -0.0142,\n",
      "         0.1715,  0.0357,  0.0107,  0.0753, -0.0232,  0.2400,  0.0752, -0.0332,\n",
      "         0.0244,  0.1322,  0.0039,  0.1442,  0.0524, -0.0306,  0.0375, -0.0058,\n",
      "        -0.0337,  0.1343, -0.0978, -0.0171,  0.0065, -0.0408,  0.0493, -0.0721,\n",
      "        -0.0165,  0.1206, -0.0069,  0.0884,  0.0728,  0.0726,  0.0386,  0.1413],\n",
      "       requires_grad=True)\n",
      "3.weight -> Parameter containing:\n",
      "tensor([[-0.2406,  0.2085, -0.1045,  ...,  0.0097, -0.0388,  0.2840],\n",
      "        [ 0.0922, -0.2183, -0.2021,  ..., -0.0121, -0.1086,  0.1455],\n",
      "        [ 0.0428, -0.0640,  0.0913,  ...,  0.0143, -0.1118, -0.3261],\n",
      "        ...,\n",
      "        [-0.0710,  0.0520,  0.3712,  ..., -0.0345,  0.2290, -0.0791],\n",
      "        [-0.2581,  0.1035,  0.3199,  ..., -0.0599,  0.1065, -0.0300],\n",
      "        [-0.1069, -0.1370, -0.3880,  ..., -0.0568,  0.0072, -0.0546]],\n",
      "       requires_grad=True)\n",
      "3.bias -> Parameter containing:\n",
      "tensor([ 0.1068, -0.1433,  0.1138,  0.1802, -0.5881,  1.0040,  0.2596, -0.0113,\n",
      "        -0.2763, -0.6917], requires_grad=True)\n"
     ]
    }
   ],
   "source": [
    "for k, v in net.named_parameters():\n",
    "    print(f'{k} -> {v}')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-03-29T03:17:20.000284Z",
     "start_time": "2024-03-29T03:17:19.986253Z"
    }
   },
   "id": "aad9cd83ee381d0e",
   "execution_count": 9
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "6e9bba0abb3b969f"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
